/**
 * https://leetcode.cn/problems/min-cost-climbing-stairs/
 */
function minCostClimbingStairs(cost: number[]): number {
  let pprev = 0
  let prev = 0;

  // dp[i] = min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2])
  for (let i = 2; i <= cost.length; i++) {
    let next = Math.min(prev + cost[i - 1], + pprev + cost[i - 2])
    pprev = prev
    prev = next
  }

  return prev
}


function minCostClimbingStairsV2(cost: number[]): number {
    let dp: number[] = new Array(cost.length + 1).fill(0)
    for (let i = 2; i <= cost.length; i++) {
      dp[i] = Math.min(dp[i - 1] + cost[i - 1], + dp[i - 2] + cost[i - 2])
    }
  
    return dp[cost.length];
  }
  